﻿/**
 * Project SEM 2 - SMS for schools
 * File author:ToanMH
 * Datetime create:14/11/2010
 * File version:1.0
 * File description:
 * 
 * Modify history:
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;

namespace sms_modem_control
{
    class UIUtilities
    {
        #region RichTextBox Helper
        //////////////////////////////////////
        /////////////////////////////////////
        // Bunch of stuff to make the richTextBox auto-scroll to the bottom. put in your class.
        ////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////
       public static  int SB_VERT = 1;
       public static  int EM_SETSCROLLPOS = 0x0400 + 222;

        [DllImport("user32", CharSet = CharSet.Auto)]
        public static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);

        [DllImport("user32", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam);

        [StructLayout(LayoutKind.Sequential)]
        public class POINT
        {
            public int x;
            public int y;

            public POINT()
            {
            }

            public POINT(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }
        ////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////
        // End of richTextBox scroll helper stuff.
        ////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////// 


        ////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////
        // Help for append text in richtext box with color
        ////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////// 
       public static void AppendRichTextBox(RichTextBox richBox,Color color, String strText){

           try
           {
               int start = richBox.TextLength;
               richBox.AppendText(strText);
               int end = richBox.TextLength;

               // Textbox may transform chars, so (end-start) != text.Length
               richBox.Select(start, end - start);
               {
                   richBox.SelectionColor = color;
                   // could set box.SelectionBackColor, box.SelectionFont too.
               }
               richBox.SelectionLength = 0; // clear
           }
           catch { 
           
           }
       }
        ////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////
        //END  Help for append text in richtext box with color
        ////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////// 
        #endregion

    }
}
